package jMiiEditor.myavatareditor.xml;

import java.io.IOException;
import jMiiEditor.mii.Mii;


public class MyAvatarEditorXMLExport
{

    public MyAvatarEditorXMLExport()
    {

    }

    public String toXML( Mii mii )
    {
        StringBuilder sb = new StringBuilder();

        try {
            toXML( sb, mii );
        }
        catch( IOException ignore ) {
            //ignore, this.
        }

        return sb.toString();
    }

    public Appendable toXML(
            Appendable anAppendable,
            Mii        mii
            ) throws IOException
    {
        XMLAppender a = new XMLAppender(anAppendable);

        a.appendLine(0,"<?xml version=\"1.0\" ?>" );
        a.appendLine(0,"<?xml-stylesheet type=\"text/xsl\" href=\"/xml/avatar.xsl\" ?>" );
        a.appendLine(0,"<!DOCTYPE avatar-collection SYSTEM \"/xml/avatar.dtd\" >" );
        a.appendLine(0,"<Avatar xmlns=\"http://www.myavatareditor.com/xml/avatar/1\">");
        a.appendLine(1,"<id>",mii.getMiiId(),"</id>" ); // {avatarData.id.toString(16).toUpperCase()}
        a.appendLine(1,"<clientID>",mii.getSystemId(),"</clientID>" ); //{avatarData.clientID.toString(16).toUpperCase()}
        a.appendLine(1,"<name>",mii.getMiiName(),"</name>" );//{avatarData.name}
        a.appendLine(1,"<creatorName>",mii.getMiiCreator(),"</creatorName>" );//{avatarData.creatorName}
        a.appendLine(1,"<birthDay>",mii.getDay(),"</birthDay>" );//{avatarData.birthDay}
        a.appendLine(1,"<birthMonth>",mii.getMonth(),"</birthMonth>" );//{avatarData.birthMonth}
        a.appendLine(1,"<gender>",mii.isGirl(),"</gender>" );//{avatarData.gender}
        a.appendLine(1,"<mingles>",mii.isMingleOff(),"</mingles>" );// {avatarData.mingles}

        a.appendLine(1,"<Beard>" );
        a.appendLine(2,"<type>",mii.getBeardType(),"</type>" );//{avatarData.beardType}
        a.appendLine(2,"<color>",mii.getFacialHairColor(),"</color>" );//{avatarData.beardColor}
        a.appendLine(1,"</Beard>" );

        a.appendLine(1,"<Body>" );
        a.appendLine(2,"<height>",mii.getHeight(),"</height>" );//{avatarData.height}
        a.appendLine(2,"<weight>",mii.getWeight(),"</weight>" );//{avatarData.weight}
        a.appendLine(1,"</Body>" );

        a.appendLine(1,"<Eye>" );
        a.appendLine(2,"<type>",mii.getEyeType(),"</type>" );//{avatarData.eyeType}
        a.appendLine(2,"<color>{avatarData.eyeColor}</color>" );
        a.appendLine(2,"<x>{avatarData.eyeX}</x>" );
        a.appendLine(2,"<y>{avatarData.eyeY}</y>" );
        a.appendLine(2,"<size>{avatarData.eyeSize}</size>" );
        a.appendLine(2,"<rotation>{avatarData.eyeRotation}</rotation>" );
        a.appendLine(1,"</Eye>" );

        a.appendLine(1,"<Eyebrow>" );
        a.appendLine(2,"<type>{avatarData.eyebrowType}</type>" );
        a.appendLine(2,"<color>{avatarData.eyebrowColor}</color>" );
        a.appendLine(2,"<x>{avatarData.eyebrowX}</x>" );
        a.appendLine(2,"<y>{avatarData.eyebrowY}</y>" );
        a.appendLine(2,"<size>{avatarData.eyebrowSize}</size>" );
        a.appendLine(2,"<rotation>{avatarData.eyebrowRotation}</rotation>" );
        a.appendLine(1,"</Eyebrow>" );

        a.appendLine(1,"<Face>" );
        a.appendLine(2,"<type>{avatarData.faceType}</type>" );
        a.appendLine(1,"</Face>" );

        a.appendLine(1,"<Glasses>" );
        a.appendLine(2,"<type>{avatarData.glassesType}</type>" );
        a.appendLine(2,"<color>{avatarData.glassesColor}</color>" );
        a.appendLine(2,"<y>{avatarData.glassesY}</y>" );
        a.appendLine(2,"<size>{avatarData.glassesSize}</size>" );
        a.appendLine(1,"</Glasses>" );

        a.appendLine(1,"<Hair>" );
        a.appendLine(2,"<type>{avatarData.hairType}</type>" );
        a.appendLine(2,"<color>{avatarData.hairColor}</color>" );
        a.appendLine(2,"<part>{avatarData.hairPart}</part>" );
        a.appendLine(1,"</Hair>" );

        a.appendLine(1,"<Head>" );
        a.appendLine(2,"<type>{avatarData.headType}</type>" );
        a.appendLine(1,"</Head>" );

        a.appendLine(1,"<Mole>" );
        a.appendLine(2,"<type>{avatarData.moleType}</type>" );
        a.appendLine(2,"<x>{avatarData.moleX}</x>" );
        a.appendLine(2,"<y>{avatarData.moleY}</y>" );
        a.appendLine(2,"<size>{avatarData.moleSize}</size>" );
        a.appendLine(1,"</Mole>" );

        a.appendLine(1,"<Mouth>" );
        a.appendLine(2,"<type>{avatarData.mouthType}</type>" );
        a.appendLine(2,"<color>{avatarData.mouthColor}</color>" );
        a.appendLine(2,"<y>{avatarData.mouthY}</y>" );
        a.appendLine(2,"<size>{avatarData.mouthSize}</size>" );
        a.appendLine(1,"</Mouth>" );

        a.appendLine(1,"<Mustache>" );
        a.appendLine(2,"<type>{avatarData.mustacheType}</type>" );
        a.appendLine(2,"<y>{avatarData.mustacheY}</y>" );
        a.appendLine(2,"<size>{avatarData.mustacheSize}</size>" );
        a.appendLine(1,"</Mustache>" );

        a.appendLine(1,"<Nose>" );
        a.appendLine(2,"<type>{avatarData.noseType}</type>" );
        a.appendLine(2,"<y>{avatarData.noseY}</y>" );
        a.appendLine(2,"<size>{avatarData.noseSize}</size>" );
        a.appendLine(1,"</Nose>" );

        a.appendLine(1,"<Shirt>" );
        a.appendLine(2,"<color>{avatarData.favoriteColor}</color>" );
        a.appendLine(1,"</Shirt>" );

        a.appendLine(1,"<Skin>" );
        a.appendLine(2,"<color>{avatarData.skinColor}</color>" );
        a.appendLine(1,"</Skin>" );
        a.appendLine(0,"</Avatar>" );

//            // add code attribute if specified
//            if (codeAttribute){
//                avatarXML.@code = new HexCodeString().write(avatarData);
//            }
//
//            // if xml is provided, add the generated XML
//            // as a child of that XML.
//            if (xml){
//                xml.appendChild(avatarXML);
//            }
//
//            return avatarXML;
        return anAppendable;
        }
}
